package cn.xzq.crm.dao;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;

import cn.xzq.crm.entity.User;


@Repository("userDaoImpl")
public class UserDaoImpl  implements UserDao {
	
	@Resource(name="hibernateTemplate")
	private HibernateTemplate hibernateTemplate;
	
	/**
	 * 查找一个用户
	 */
	@SuppressWarnings("all")
	public User findOneUser(User user) {
		String hql = "from User where username=?";
		List<User> list = (List<User>) hibernateTemplate.find(hql, user.getUsername());
		//返回list对象到user
		if(list==null && list.size()!= 0){
			return null;
		}
		return list.get(0);
	}

	/**
	 * 添加一个用户
	 */
	@Override
	public void add() {
		
	}
	
	/**
	 * 查找所有用户
	 * @return
	 */
	public List<User> findAll(){
		List<User> list = (List<User>) hibernateTemplate.find("from User");
		return list;
	}
	
	/**
	 * 根据id查找一个用户
	 * @param user
	 * @return
	 */
	public User findOneById(String uid){
		User user = hibernateTemplate.get(User.class, uid);
		return user;
	}
}
